package com.sfx.concurrent.demo.concurrent.pattern.GuardedObjectEncapsulation;

import lombok.extern.slf4j.Slf4j;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2022-12-31
 * Time: 15:28
 */

//送信
@Slf4j(topic = "c.Postman")
public class Postman extends Thread{
    private MailBoxes mailBoxes = new MailBoxes();
    private int id;
    private String mail;

    public Postman(String name, int id, String mail) {
        super(name);
        this.id = id;
        this.mail = mail;
    }

    @Override
    public void run() {
        log.debug("开始送信");
        //通过id获取邮箱
        GuardedObject guardedObject = mailBoxes.GetGuardedObject(id);
        log.debug("邮箱id{},信息{}",guardedObject.getId(),mail);
        guardedObject.complete(mail);
    }
}
